using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Xml.Serialization;
using System.Xml;
using System.Collections;
using System.Drawing;

namespace TVDesigner.Entities.Elements
{
    
    [XmlRoot("Screen")]
    public class Screen : GenericComponent
    {
        private string _ScreenBlue;
        private string _ScreenYellow;
        private string _ScreenRed;
        private string _ScreenGreen;

        
        private List<HIcon> _HIcons;        
        private List<HButton> _HButtons;        
        private List<HText> _HTexts;
        private ScreenResize _ScreenResize;

        [XmlIgnoreAttribute()]
        private ProjectXlet _Project;

        #region Propriedades

        [XmlElementAttribute("ScreenResize")]
        public ScreenResize ScreenResize
        {
            get
            {
                return _ScreenResize;
            }
            set
            {
                _ScreenResize = value;
            }
        }

        [XmlIgnoreAttribute()]
        public List<GenericComponent> Components
        {
            get
            {
                List<GenericComponent> list = new List<GenericComponent>();
                foreach (HIcon hi in _HIcons)
                {
                    list.Add(hi);
                }
                foreach (HButton hi in _HButtons)
                {
                    list.Add(hi);
                }
                foreach (HText hi in _HTexts)
                {
                    list.Add(hi);
                }

                if (_ScreenResize != null)
                {
                    list.Add(_ScreenResize);
                }
                return list;
            }
        }
        
        [XmlElementAttribute("HIcon")]
        public List<HIcon> HIcons
        {
            get { return _HIcons; }
            set { _HIcons = value; }
        }
        [XmlElementAttribute("HButton")]
        public List<HButton> HButtons
        {
            get { return _HButtons; }
            set { _HButtons = value; }
        }
        [XmlElementAttribute("HText")]
        public List<HText> HTexts
        {
            get { return _HTexts; }
            set { _HTexts = value; }
        }

        [XmlElementAttribute("ScreenGreen")]
        public string ScreenGreen
        {
            get { return _ScreenGreen; }
            set { _ScreenGreen = value; }
        }
        [XmlElementAttribute("ScreenRed")]
        public string ScreenRed
        {
            get { return _ScreenRed; }
            set { _ScreenRed = value; }
        }
        [XmlElementAttribute("ScreenYellow")]
        public string ScreenYellow
        {
            get { return _ScreenYellow; }
            set { _ScreenYellow = value; }
        }
        [XmlElementAttribute("ScreenBlue")]
        public string ScreenBlue
        {
            get { return _ScreenBlue; }
            set { _ScreenBlue = value; }
        }
        #endregion

        public Screen() : base()
        {
            _HIcons = new List<HIcon>();
            _HButtons = new List<HButton>();
            _HTexts = new List<HText>();

            _Size = new Size(50, 50);
            _Location = new Point(10, 10);
        }

        #region Public Methods

        public void SetProject(ProjectXlet project)
        {
            _Project = project;
        }
        public ProjectXlet GetProject()
        {
            return _Project;
        }

        public bool AddGenericComponent(GenericComponent gc)
        {
            bool ok = true;
            gc.ParentScreen = this;
            if (gc is HButton)
            {
                _HButtons.Add(gc as HButton);
            }
            else if (gc is HIcon)
            {
                _HIcons.Add(gc as HIcon);
            }
            else if (gc is HText)
            {
                _HTexts.Add(gc as HText);
            }
            else if (gc is ScreenResize)
            {
                if (_ScreenResize == null)
                {
                    _ScreenResize = gc as ScreenResize;
                }
                else
                {
                    ok = false;
                }
            }
            return ok;
        }

        public void RemoveGenericComponent(GenericComponent gc)
        {
            if (gc is HButton)
            {
                _HButtons.Remove(gc as HButton);
            }
            else if (gc is HIcon)
            {
                _HIcons.Remove(gc as HIcon);
            }
            else if (gc is HText)
            {
                _HTexts.Remove(gc as HText);
            }
            else if (gc is ScreenResize)
            {
                if (_ScreenResize == gc)
                {
                    _ScreenResize = null;
                }
            }
        }

        public List<string> GetConnectedScreenNames()
        {
            List<string> screensNames = new List<string>();
            foreach (HButton button in _HButtons)
            {
                screensNames.Add(button.ScreenName);
            }

            return screensNames;
        }

        //public void ClearComponents()
        //{
        //    _HButtons.Clear();
        //    _HIcons.Clear();
        //    _HTexts.Clear();
        //}
        
        #endregion

        //#region override
        //public override bool Equals(object obj)
        //{
        //    if (obj != null && obj.GetType() == this.GetType())
        //    {
        //        return (((Screen)obj).Name.Equals(this.Name));
        //    }
        //    return false;
        //}
        //#endregion


    }
}
